<?php

class Domain_KPI {

    function getlist($rule, $pageConfig) {

        $db = new Model_KPI();
        $where = [];
        if (isset($rule['key'])) {
            $where["name LIKE ?"] = "%" . $rule['key'] . "%";
//            $where["organize LIKE ?"]= "%".$rule['key']."%";
//            $where["sort LIKE ?"]= "%".$rule['key']."%";
        }
        if (isset($rule['isshow'])) $where["isshow"] = $rule['isindex'] ? "1" : "0";
        if (isset($rule['ispublic'])) $where["ispublic"] = $rule['ispublic'] ? "1" : "0";


        $offset = ($pageConfig['page'] - 1) * $pageConfig['pageMax'];
        $limit = $pageConfig['pageMax'];

        $orderby = ["name desc", "name asc", "organize desc", "organize asc", "online_date desc", "online_date asc"];

        return [
            "list"  => $db->lists($where, $offset, $limit, $orderby[$pageConfig['orderby']]),
            "total" => $db->count($where, $offset, $limit, $orderby[$pageConfig['orderby']])
        ];


    }

    public function hasid($id) {
        $db = new Model_KPI();
        return $db->hasid($id) > 0;
    }

    public function isadded($contract_no) {
        $db = new Model_KPI();
        return $db->isadded($contract_no) > 0;
    }

    public function add($data) {
        $db = new Model_KPI();
        $data['status'] = 0;
        $data['ctime'] = DI()->helper->getTime();
        return $db->add($data);
    }
    public function edit($data,$id) {
        $db = new Model_KPI();
        $data['ctime'] = DI()->helper->getTime();
        return $db->edit($data,$id);
    }
    public function info($id) {
        $db = new Model_KPI();
        $data= $db->getById($id);
        if(!$data)return false;

    }
    public function delete($id) {
        $db = new Model_KPI();
        return $db->delete($id);
    }


    public function organizesList() {
        $db = new Model_KPI();
        return $db->organizes();
    }


}
